#!/bin/bash
# export DISPLAY=:1  # 设置显示环境变量
# export GSETTINGS_BACKEND=dconf  # 设置 gsettings 的后端为 dconf

# gsettings set org.gnome.system.proxy mode 'none'

# touch /home/wj/abc.txt



REAL_UID=$(id --real --user)
PID=$(pgrep --euid $REAL_UID gnome-session | head -n 1)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2- | sed -e "s/\x0//g")

proxy_mode=$(gsettings get org.gnome.system.proxy mode)

# toggle
if [ "$proxy_mode" = "'none'" ] ; then
    gsettings set org.gnome.system.proxy mode 'manual'
else
    gsettings set org.gnome.system.proxy mode 'none'
fi
